--[[
 -- *名称:AnalyzerCounter
 -- *描述:计数器
 -- *版权:Copyright © 2016-2018 深圳市三只小熊科技有限公司 版权所有
 -- *作者:Administrator
 -- *创建日期:2017-11-07
 -- *修改日期:2017-11-07
 ]]
local AnalyzerCounter = pokercore.class();
---
 -- [ctor 默认类的构造方法]
 -- @DateTime 2017-09-20
 -- @param     [description]
 -- @return    [description]
 --
function AnalyzerCounter:ctor(...)
   --[[
    * 点数value ---》 个数，记录某点数的数量 <br>
	* 比如出牌 3334448A 最终会记录 3有3张，4有3张，8有1张，14有1张这样
    ]]
   self.counter = {} ;
end


--[[
 -- [addValueCount 增加某点数的个数]
 -- @DateTime 2017-11-07
 -- @param    value [description]
 ]]
function AnalyzerCounter:addValueCount(value)
   local count = self.counter[value] ;
   if not count then
   	  self.counter[value] = 1 ;
   else
   	  self.counter[value] = self.counter[value] + 1 ;
   end
end

---
 -- [getValueCount 获取某点数的个数]
 -- @DateTime 2017-11-07
 -- @param    value [description]
 -- @return    [description]
 --
function AnalyzerCounter:getValueCount(value)
   return self.counter[value] or 0 ;
end

---
 -- [getValuesInCount 获取张数为count 的点数值]
 -- @DateTime 2017-11-07
 -- @param    count [description]
 -- @return    [description]
 --
function AnalyzerCounter:getValuesInCount(count)
  	local numbers =  {} ;
  	for k,v in pairs(self.counter) do
  		if v == count then
  			table.insert(numbers,k);
  		end
  	end
  	table.sort(numbers,function(a,b)
        return a<b ;
  	end)

    return numbers ;
end

--[[
 -- [getAllValues 获取张数为count 的点数值] 获取的键的集合
 -- @DateTime 2017-11-07
 -- @return   [description]
 ]]
function AnalyzerCounter:getAllValues()
    local t = {} ;
    for k,v in pairs(self.counter) do
       table.insert(t,k);
    end
    table.sort(t,function(a,b)
      return a<b ;
    end);
    return t;
end


function AnalyzerCounter:clear()
    self.counter = {} ;
end

---
 -- [hasJoker 是否有王]
 -- @DateTime 2017-11-07
 -- @return   [description]
 --
function AnalyzerCounter:hasJoker()
   if self:getValueCount(PokerGameConstant.RED_JOKER_SHAPE_VALUE) > 0
   	 or self:getValueCount(PokerGameConstant.BLACK_JOKER_SHAPE_VALUE) > 0 then
   	   return true ;
   end

   return false ;
end

function AnalyzerCounter:getCounter()
    return self.counter ;
end

function AnalyzerCounter:setCounter(counter)
    self.counter = counter;
end

---
 -- [dtor 默认类的销毁方法]
 -- @DateTime 2017-09-20
 -- @param     [description]
 -- @return    [description]
 --
function AnalyzerCounter:dtor(...)
  
end

return AnalyzerCounter;

